package com.group.controller;

import com.group.entity.CommonResult;
import com.group.entity.wms.ClassifyEntity;
import com.group.service.ClassifyService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/classify")
public class ClassifyController {
    @Resource
    private ClassifyService classifyService;

    @GetMapping("/findAll")
    public CommonResult<?> findAll(){
        return CommonResult.success(this.classifyService.findAll(),"请求成功");
    }
    @PostMapping("/add")
    public CommonResult<?> add(@RequestBody ClassifyEntity classifyEntity){

       return this.classifyService.add(classifyEntity)>=1?CommonResult.success(null,"分类添加成功"):CommonResult.error(499,"网络异常");
    }

    @PutMapping("/update")
    public CommonResult<?> update(@RequestBody ClassifyEntity classifyEntity){
        return this.classifyService.update(classifyEntity)>=1?CommonResult.success(null,"分类信息修改成功"):CommonResult.error(499,"网络异常");
    }

    @DeleteMapping("/delete/{id}")
    public CommonResult<?> delete(@PathVariable("id")Long id){

        return this.classifyService.delete(id)>=1?CommonResult.success(null,"分类删除成功"):CommonResult.error(499,"网络异常");
    }
}
